package com.xyht.medicine_management_system.modules.user.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.user.entity.req.MmsUserExamineAllowReq;
import com.xyht.medicine_management_system.modules.user.entity.req.MmsUserExamineApplyReq;
import com.xyht.medicine_management_system.modules.user.service.MmsUserExamineService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 用户审核表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-11-16
 */
@RestController
@SecretBody
@RequestMapping("/user/examine")
public class MmsUserExamineController {
    @Resource
    private MmsUserExamineService mmsUserExamineService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @PostMapping("/apply")
    @ApiModelProperty(value = "用户认证申请")
    public ResponseResult AuthExamineApply(@RequestBody MmsUserExamineApplyReq applyReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserExamineService.AuthExamineApply(applyReq, user_id);
    }

    @GetMapping("/applyHistory")
    @ApiModelProperty(value = "用户认证历史查看")
    public ResponseResult getApplyHistory(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                          HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserExamineService.getApplyHistory(pageNum, pageSize, user_id);
    }

    @PostMapping("/allow")
    @ApiModelProperty(value = "认证审批")
    public ResponseResult allowUserApply(@RequestBody MmsUserExamineAllowReq allowReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserExamineService.allowUserApply(allowReq, user_id);
    }

    @GetMapping("/examineList")
    @ApiModelProperty(value = "认证申请列表")
    public ResponseResult getExamineList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "examineType", required = false) Integer examineType,
                                         @RequestParam(value = "applyType", required = false) Integer applyType
    ) {
        return mmsUserExamineService.getExamineList(pageNum, pageSize, examineType, applyType);
    }

    @GetMapping("/detail")
    @ApiModelProperty(value = "认证申请详情")
    public ResponseResult getExamineDetail(@RequestParam("id") String id) {
        return mmsUserExamineService.getExamineDetail(id);
    }

}

